package cn.ftx.result.exception;


import cn.ftx.result.data.Result;
import cn.ftx.result.enums.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * <p>
 *
 * </p>
 *
 * @author AUTHER
 * @since 2021-04-29
 */
@RestControllerAdvice
@Slf4j
public class RRExceptionHandler {

    /**
     * 自定义异常
     *
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler(RRException.class)
    public Result handleRRException(RRException e) {
        Result r = new Result();
        r.setCode(e.getCode());
        r.setMessage(e.getMsg());
        return r;
    }
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        log.error(e.getMessage(), e);
        return Result.failure(ResultCode.ERROR,e.getMessage());
    }
    @ResponseBody
    @ExceptionHandler(ArithmeticException.class)
    public Result handleException(ArithmeticException e) {
        log.error(e.getMessage(), e);
        return Result.failure(ResultCode.ERROR,e.getMessage());
    }
}
